/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODECPP_CRYPTO_HMAC_H_
#define NODECPP_CRYPTO_HMAC_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstddef>
#include <cstdint>
#include <openssl/hmac.h>
#include <openssl/sha.h>
#include <NodeCpp/Macros.h>

namespace NodeCpp {
namespace Crypto {
	class BigNumber;

	class HmacHash
	{
	public:
		const static int SEED_KEY_SIZE = 16;

		HmacHash(void);
		~HmacHash(void);

		void UpdateBigNumber(BigNumber* _Bn);
		void UpdateData(const std::uint8_t* _Data, int _Size);
		void Initialize(void);
		void Finalize(void);
        const std::uint8_t* digest(void) const { return Digest_; }
		int length(void) const { return SHA_DIGEST_LENGTH; }

	private:
		HMAC_CTX Ctx_;
		std::uint8_t Key_[SEED_KEY_SIZE];
		std::uint8_t Digest_[SHA_DIGEST_LENGTH];
		DISALLOW_COPY_AND_ASSIGN(HmacHash);
	};

}}

#endif /* NODECPP_CRYPTO_HMAC_H_ */


